<?php
namespace app\base\controller;
use app\rbac\model\PrivilegeM;
use think\Controller;
use think\Log;
use think\Session;

class Base extends Controller
{
        public  function __construct()
        {
            parent::__construct();
            $admin_id = Session::get('admin_id');
            $m = $this->request->module();
            $c = ucfirst($this->request->controller());
            $a = $this->request->action();
            if(!$admin_id){
                $this->redirect('base/login/login');
            }
            $priModel = new PrivilegeM();
            //传送菜单信息
            $btnData = $priModel->getBtn();
            $this->assign(['btnData'=>$btnData]);
            //except例外的
            $except = [
                ['base','Index','index'],
                ['base','Index','editprofile'],
                ['base','Index','setpassword'],
            ];
//            // 所有管理员都可以进入后台的页面
            foreach($except as $v)
            {
                if($m == $v[0] && $c == $v[1] && $a == $v[2])
                {
                    return true;
                }
            }
            if($admin_id == 1)
            {//超级管理员
                return true;
            }
            if(!$priModel->chkPri($admin_id,$m,$c,$a))
            {
                $this->error('无权查看！');
            }
        }
}
